Skip to content

Replace Chosen with native datalist for sponsor chapter filter - #2820

Open
mroderick wants to merge 4 commits into
masterfrom
feature/replace-chosen-sponsors-filter-clean
Open

Replace Chosen with native datalist for sponsor chapter filter#2820
mroderick wants to merge 4 commits into
masterfrom
feature/replace-chosen-sponsors-filter-clean

Conversation

@mroderick

@mroderick mroderick commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

What

Replaces Chosen.js selects with a reusable ChapterPickerComponent that uses native HTML datalist + text input with autocomplete="off".

New: ChapterPickerComponent

A reusable ViewComponent that renders a text input backed by a <datalist> with chapter names as values:

render ChapterPickerComponent.new(
  name: 'sponsors_search[chapter]',
  chapters: @chapters,
  placeholder: 'Filter by chapter'
)

The input shows the chapter name the user selects (not an ID), while the controller does a case-insensitive name lookup to resolve it. The autocomplete="off" prevents browser autofill from fighting the datalist suggestions.

Applied to

  1. Sponsors filter (admin/sponsors/index) — replaces collection_select with chosen-select class
  2. Workshop form (admin/workshops/_shared_form) — replaces f.association :chapter select

SponsorsSearch

Continues to do case-insensitive name lookup for chapter filtering (no change from the existing behaviour — the datalist now submits the name directly instead of an ID).

Why

Chosen is abandoned. This removes a JavaScript dependency and uses built-in browser autocomplete instead. The component is reusable — any form that needs single-chapter selection can use it.

Testing

  • bundle exec rspec spec/queries/sponsors_search_spec.rb
  • bundle exec rspec spec/features/admin/filtering_sponsors_list_spec.rb
  • bundle exec rspec spec/features/admin/workshops_spec.rb
  • bundle exec rspec spec/components/chapter_picker_component_spec.rb

@mroderick
mroderick marked this pull request as ready for review August 29, 2026 13:05
@mroderick
mroderick requested a review from olleolleolle August 30, 2026 05:28
@mroderick
mroderick marked this pull request as draft August 30, 2026 07:08
@mroderick
mroderick force-pushed the feature/replace-chosen-sponsors-filter-clean branch 5 times, most recently from 9212787 to ddafafe Compare August 30, 2026 10:27
Adds case-insensitive name-based chapter lookup as a fallback when
filtering sponsors. Supports both chapter IDs (for programmatic use)
and chapter names (for human-friendly filtering).
Reusable ViewComponent for single-chapter selection using native
HTML datalist. Renders a text input with autocomplete=off backed
by a datalist of chapter names. Sanitises the input name into a
valid HTML id for the datalist element.
Replaces the chosen-select collection_select with the reusable
ChapterPickerComponent. Also switches from simple_form_for to
form_with for the filter form.
Replaces f.association :chapter select with ChapterPickerComponent.
Adds resolve_chapter_name_to_id helper to the controller so the
form can submit chapter names while the model still receives IDs.
@mroderick
mroderick force-pushed the feature/replace-chosen-sponsors-filter-clean branch from ddafafe to 3788be9 Compare August 30, 2026 10:34
@mroderick
mroderick marked this pull request as ready for review August 30, 2026 10:37
@@ -0,0 +1,15 @@
# frozen_string_literal: true

class ChapterPickerComponent < ViewComponent::Base

@olleolleolle olleolleolle Aug 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: We should have an ApplicationComponent base class, I think, for an easier control point. It won't change anything right now, but it's neat to have prepared.

require 'view_component/test_helpers'

RSpec.describe ChapterPickerComponent do
include ViewComponent::TestHelpers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: we should make it so that each spec/components/ test get these by dint of having derived RSpec Metadata about their "type".

Or, check whether that's already true, and these helpers are already included.

@olleolleolle olleolleolle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like a good datalist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants